<?php
/**
 * User: Hufeng
 * Date: 2017/08/29 19:48
 * Desc: 交易所Model
 */
namespace App\Model;
use SasPHP\SqlModel;

class StockHandicapModel extends SqlModel{
    protected $dbName = 'stock_handicap';

    public function __construct(){
        parent::__construct('DB_SERVER');
    }

    function insertData($data){
        $this->dbConn->insert($this->dbName,$data);
        return $this->dbConn->id();
    }

    function editData($where,$data){
        $this->dbConn->update($this->dbName,$data,$where);
    }

    function delData($data){
        $this->dbConn->delete($this->dbName, $data);
    }

    function findData($where,$fields='*'){
        $res = $this->dbConn->get($this->dbName,$fields,$where);
        return $res;
    }

    function queryData($where,$fields='*'){
        $res = $this->dbConn->select($this->dbName,$fields,$where);
        return $res;
    }
    //获取统计数据
    public function getTotalNum($where){
        $res = $this->dbConn->count($this->dbName,$where);
        return $res;
    }
    //sum数据
    public function sumData($where,$param){
        $res = $this->dbConn->sum($this->dbName,$param,$where);
        return $res;
    }

    //获取股票当日最高，最低价格
    public function rangPrice($sid,$range){
        $thdModel = new TradeDealhistoryModel();
        $ycPrice = $thdModel->yclosePrice($sid);
        $maxPrice = round($ycPrice+($ycPrice*$range/100),2);
        $minPrice = round($ycPrice-($ycPrice*$range/100),2);
        return ['maxPrice'=>$maxPrice,'minPrice'=>$minPrice];
    }

    //最新综合指数
    public function compQuota($tpId){
        $queryData = $this->queryData(['tpid'=>$tpId,'status'=>1],['new_price','stock_num']);
        $total = 0;
        foreach ($queryData as $val){
            $total += $val['new_price']*$val['stock_num'];
        }
        return round($total/10000000,2);
    }
}
